package com.pshcp.api;

import com.framework.base.PageList;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.exception.BizException;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.tool.CommonTool;
import com.pshcp.ao.label.LabelListAO;
import com.pshcp.domain.dto.LabelDTO;
import com.pshcp.domain.model.Label;
import com.pshcp.service.LabelService;
import com.pshcp.tool.LabelTool;
import com.pshcp.vo.label.LabelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 通用接口-标签
 * @Author: xiaoche
 * @Date: 2022/11/3 23:55
 */
@Api(tags = {"通用接口-标签"})
@Slf4j
@RestController
@RequestMapping("/api/label")
public class LabelAPI {

    @Autowired
    private LabelService labelService;

    @ApiOperation("获取标签列表")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.SELECT, desc = "获取标签列表")
    @PostMapping("getLabelList")
    public ResultDTO<List<LabelVO>> getLabelList(@RequestBody LabelListAO labelListAO) throws BizException {
        CommonTool.checkString(labelListAO.getType(), "10080001");
        LabelDTO labelDTO = LabelTool.buildLabelList(labelListAO);
        PageList<Label> pageList = labelService.list(labelDTO);
        List<Label> items = pageList.getItems();
        List<LabelVO> list = CommonTool.copyPropertiesList(items, LabelVO.class);
        return ResultBuilder.success(list);
    }
}
